package cn.com.ddapp.ddm.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;

import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.com.ddapp.ddm.R;
import cn.com.ddapp.ddm.bean.SlidingSmallBean;


public class SlidingsiteAdpter extends BaseAdapter {
    private Context mContext;
    private List<SlidingSmallBean.siteList> mLists ;
    private LayoutInflater layoutInflater;

    public SlidingsiteAdpter(Context context, List<SlidingSmallBean.siteList> lists) {
        mContext = context;
        mLists = lists;
        layoutInflater=LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return mLists != null ? mLists.size():0;
    }

    @Override
    public Object getItem(int i) {
        return mLists.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }
    public void clear(){
        for (int i = 0; i < mLists.size(); i++) {
            mLists.get(i).setCheck(false);
        }
        notifyDataSetChanged();
    }
    public void addView(List<SlidingSmallBean.siteList> ll){
        if(ll.size()<=0){
            return;
        }else{
            mLists.addAll(ll);
        }
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder holder=null;
        if(convertView == null){
            convertView= layoutInflater.inflate(R.layout.sliding_name_item,null);
            holder=new ViewHolder(convertView);
            convertView.setTag(holder);
            AutoUtils.auto(convertView);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }

        holder.slidingbig_name.setText(mLists.get(position).getName());
        holder.slidingbig_name.setChecked(mLists.get(position).isCheck());

        return convertView;
    }


    static class ViewHolder{
        @BindView(R.id.slidingsmall_name)
        CheckBox slidingbig_name;


        public ViewHolder(View view){
            ButterKnife.bind(this,view);
        }
    }
}
